/*
*	Copyright (C) 2014  Julio Montes, Mario Carrillo
*	
*	Julio Montes e-mail: imc.coder@gmail.com 
*
*	Mario Carrillo e-mail: mario_90ago@live.com.mx
*
*	BSD 3-Clause License
*/

#ifndef ALLIANCE_PROCESSMGR_H
#define ALLIANCE_PROCESSMGR_H

#include "sdk/include/mgr.h"

#include "alliance/include/tool.h"

#include <wx/wx.h>
#include <wx/process.h>

namespace alliance
{
    class Project;

    typedef void(* CallbackFunction)( bool, size_t, void * );

    class ProcessManager : public sdk::Mgr<ProcessManager>, public wxEvtHandler
    {
        friend class sdk::Mgr<ProcessManager>;
    public:
        void CompileProject( Project *project, CallbackFunction cbFunction, void *caller );
        void StopCompile();
        bool OnClose();
        void LaunchViewer( const Project *project, const Tool &viewer );
    protected:
    private:
        ProcessManager();
        virtual ~ProcessManager();

        void ExecuteNextTool();

        void OnEndProcess( wxProcessEvent &evt );

        size_t m_nextTool;
        bool m_isBusy;
        Project *m_project;
        int m_lastExitCode;
        void *m_caller;
        wxProcess *m_process;
        bool m_stopCompile;
        CallbackFunction m_cbFunction;

    };
}

#endif //ALLIANCE_PROCESSMGR_H
